package Data;

import JDBC.DBUtil;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * description:
 * author: 柳胜酉
 * 2022/7/7
 */
public class ClassJTable extends DBUtil {
    private static JTextField textField1;
    private static JScrollPane scrollPane1;
    private static JTable table1;
    private static DefaultTableModel dtm = null;
    static String grade = null;
    static String teacher = null;

//    public static void head(DefaultTableModel dtm){
//        String[] head = {"班级", "年级", "人数", "教师"};
//        dtm = new DefaultTableModel();
//        //遍历数组，确定你有几列
//        for (int i = 0; i < head.length; i++) {
//            dtm.addColumn(head[i]);
//        }
//        //fillTable();//表格内容的填充
//        table1 = new JTable(dtm);
//        scrollPane1 = new JScrollPane(table1);
//    }

    //    public static java.util.List<ClassData> getAllDate() {
//        java.util.List<ClassData> list = new ArrayList<>();
//        try {
//            ClassData classData = null;
//            ResultSet rs = getRs("select * from user_class");
//            while (rs.next()) {
//                classData = new ClassData();
//                String sclass = rs.getString("s_class");
//                String sgrade = rs.getString("s_grade");
//                String snum = rs.getString("s_num");
//                String steacher = rs.getString("s_teacher");
//
//                classData.setSclass(sclass);
//                classData.setSgrade(sgrade);
//                classData.setSnum(snum);
//                classData.setSteacher(steacher);
//
//                list.add(classData);
//            }
//            return list;
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return list;
//    }
    //************************************************ getAllDate **********************************************************//
    public static java.util.List<Data> getAllDate(String table) {
        java.util.List<Data> list = new ArrayList<>();
        try {
            Data data = null;
            ResultSet rs = getRs("select * from " + table);
            while (rs.next()) {
                if (table == "user_class") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_num");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_course") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_stu") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_class");
                    String data4 = rs.getString("s_grade");
                    String data5 = rs.getString("s_major");

                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);
                    data.setData5(data5);

                    list.add(data);

                } else if (table == "user_select_s") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_select_t") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_score") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_score");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);
                } else if (table == "user_info") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                } else if (table == "user_info_t") {
                    data = new Data();
                    String data1 = rs.getString("t_no");
                    String data2 = rs.getString("t_name");
                    String data3 = rs.getString("t_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                } else if (table == "user_course_public") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);
                } else if (table == "user_course_f") {
                    data = new Data();
                    String data1 = rs.getString("s_course");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_teacher");
                    String data4 = rs.getString("s_semester");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);
                }
            }
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    public static java.util.List<Data> getAllDate(String table, String d) {
        String d1 = null;
        String d2 = null;
        String d3 = null;
        if (table == "user_class") {
            d1 = "s_class";
        } else if (table == "user_course") {
            d1 = "s_course";
        } else if (table == "user_stu") {
            d1 = "s_no";
        } else if (table == "user_select_s") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_select_t") {
            d1 = "s_class";
            d2 = "s_course";
        } else if (table == "user_score") {
            d1 = "s_no";
        } else if (table == "user_info") {
            d1 = "s_name";
        } else if (table == "user_info_t") {
            d1 = "t_name";
        }

        java.util.List<Data> list = new ArrayList<>();
        try {
            Data data = null;
            ResultSet rs = getRs("select * from " + table + " where " + d1 + " ='" + d + "'");
            System.out.println("196");
            System.out.println("select * from " + table + " where " + d1 + "='" + d + "'");
            while (rs.next()) {
                if (table == "user_class") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_num");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_course") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_stu") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_class");
                    String data4 = rs.getString("s_grade");
                    String data5 = rs.getString("s_major");

                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);
                    data.setData5(data5);

                    list.add(data);

                } else if (table == "user_select_s") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_select_t") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data3 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData3(data3);

                    list.add(data);

                } else if (table == "user_score") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_score");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);
                } else if (table == "user_info") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                } else if (table == "user_info_t") {
                    data = new Data();
                    String data1 = rs.getString("t_no");
                    String data2 = rs.getString("t_name");
                    String data3 = rs.getString("t_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                }
            }
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    public static java.util.List<Data> getAllDate(String table, String d, String m) {
        String d1 = null;
        String d2 = null;
        String d3 = null;
        if (table == "user_class") {
            d1 = "s_class";
        } else if (table == "user_course") {
            d1 = "s_course";
        } else if (table == "user_stu") {
            d1 = "s_no";
        } else if (table == "user_select_s") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_select_t") {
            d1 = "s_course";
        } else if (table == "user_score") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_course_public") {
            d1 = "s_class";
            d2 = "s_course";
            d3 = "s_semester";
        }

        java.util.List<Data> list = new ArrayList<>();
        try {
            Data data = null;
            ResultSet rs = getRs("select * from " + table + " where " + d1 + " = '" + d + "' and " + d2 + " = '" + m + "'");
            System.out.println("294");
            System.out.println("select * from " + table + " where " + d1 + " = '" + d + "' and " + d2 + " = '" + m + "'");
            while (rs.next()) {
                if (table == "user_class") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_num");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_course") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_stu") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_class");
                    String data4 = rs.getString("s_grade");
                    String data5 = rs.getString("s_major");

                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);
                    data.setData5(data5);

                    list.add(data);

                } else if (table == "user_select_s") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_select_t") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_score") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_score");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);
                } else if (table == "user_info") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                } else if (table == "user_info_t") {
                    data = new Data();
                    String data1 = rs.getString("t_no");
                    String data2 = rs.getString("t_name");
                    String data3 = rs.getString("t_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                }
            }
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    public static java.util.List<Data> getAllDate(String table, String d, String m, String n) {
        String d1 = null;
        String d2 = null;
        String d3 = null;
        if (table == "user_class") {
            d1 = "s_class";
        } else if (table == "user_course") {
            d1 = "s_course";
        } else if (table == "user_stu") {
            d1 = "s_no";
        } else if (table == "user_select_s") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_select_t") {
            d1 = "s_course";
        } else if (table == "user_score") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_course_public") {
            d1 = "s_class";
            d2 = "s_course";
            d3 = "s_semester";
        }

        java.util.List<Data> list = new ArrayList<>();
        try {
            Data data = null;
            ResultSet rs = getRs("select * from " + table + " where " + d1 + " = '" + d + "' and " + d2 + " = '" + m + "' and " + d3 + " = '" + n + "'");
            System.out.println("294");
            System.out.println("select * from " + table + " where " + d1 + " = '" + d + "' and " + d2 + " = '" + m + "' and " + d3 + " = '" + n + "'");
            while (rs.next()) {
                if (table == "user_class") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_num");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_course") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_teacher");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);

                } else if (table == "user_stu") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_class");
                    String data4 = rs.getString("s_grade");
                    String data5 = rs.getString("s_major");

                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);
                    data.setData5(data5);

                    list.add(data);

                } else if (table == "user_select_s") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_select_t") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_course");
                    data.setData1(data1);
                    data.setData2(data2);

                    list.add(data);

                } else if (table == "user_score") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_score");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);

                    list.add(data);
                } else if (table == "user_info") {
                    data = new Data();
                    String data1 = rs.getString("s_no");
                    String data2 = rs.getString("s_name");
                    String data3 = rs.getString("s_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                } else if (table == "user_info_t") {
                    data = new Data();
                    String data1 = rs.getString("t_no");
                    String data2 = rs.getString("t_name");
                    String data3 = rs.getString("t_password");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);

                    list.add(data);
                } else if (table == "user_couese_public") {
                    data = new Data();
                    String data1 = rs.getString("s_class");
                    String data2 = rs.getString("s_grade");
                    String data3 = rs.getString("s_course");
                    String data4 = rs.getString("s_teacher");
                    String data5 = rs.getString("s_semester");
                    data.setData1(data1);
                    data.setData2(data2);
                    data.setData3(data3);
                    data.setData4(data4);
                    data.setData5(data5);

                    list.add(data);
                }
            }
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    //************************************************ fillTable **********************************************************//
    public static void fillTable(DefaultTableModel dtm, String table) {
        List<Data> list = getAllDate(table);
        for (int i = 0; i < list.size(); i++) {
            Data data = list.get(i);

            if (table == "user_class") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_course") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_stu") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4(), data.getData5()});
            } else if (table == "user_select_s") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2()});
            } else if (table == "user_select_t") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2()});
            } else if (table == "user_score") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_info") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            } else if (table == "user_info_t") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            } else if (table == "user_course_public") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_course_f") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            }
        }
    }

    public static void fillTable(DefaultTableModel dtm, String table, String d1) {
        List<Data> list = getAllDate(table, d1);
        for (int i = 0; i < list.size(); i++) {
            Data data = list.get(i);
            if (table == "user_class") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_course") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_stu") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4(), data.getData5()});
            } else if (table == "user_select_t") {

            } else if (table == "user_select_s") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2()});
            } else if (table == "user_score") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_info") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            } else if (table == "user_info_t") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            }
        }
    }

    public static void fillTable(DefaultTableModel dtm, String table, String d1, String d2) {
        List<Data> list = getAllDate(table, d1, d2);
        for (int i = 0; i < list.size(); i++) {
            Data data = list.get(i);
            if (table == "user_class") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_course") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_stu") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4(), data.getData5()});
            } else if (table == "user_select_t") {

            } else if (table == "user_select_s") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2()});
            } else if (table == "user_score") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_info") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            } else if (table == "user_info_t") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            }
        }
    }

    public static void fillTable(DefaultTableModel dtm, String table, String d1, String d2, String d3) {
        List<Data> list = getAllDate(table, d1, d2, d3);
        for (int i = 0; i < list.size(); i++) {
            Data data = list.get(i);
            if (table == "user_class") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_course") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_stu") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4(), data.getData5()});
            } else if (table == "user_select_t") {

            } else if (table == "user_select_s") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2()});
            } else if (table == "user_score") {
                //添加数据 行
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            } else if (table == "user_info") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            } else if (table == "user_info_t") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3()});
            } else if (table == "user_course_public") {
                dtm.addRow(new Object[]{data.getData1(), data.getData2(), data.getData3(), data.getData4()});
            }
        }
    }

    //************************************************ delete **********************************************************//
    public static boolean delete(String table, String data1) {

        boolean flag;
        if (checked(table, data1)) {
            flag = true;
            try {
                if (table == "user_class") {
                    String sql = "delete from " + table + " where s_class = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_course") {
                    String sql = "delete from " + table + " where s_course = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_stu") {
                    String sql = "delete from " + table + " where s_no = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_select") {
                    String sql = "delete from " + table + " where s_select = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_score") {
                    String sql = "delete from " + table + " where s_score = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_course_f") {
                    String sql = "delete from " + table + " where s_course = '" + data1 + "'";
                    sm.executeUpdate(sql);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            flag = false;
        }
        return flag;
    }


    public static boolean delete(String table, String data1, String data2) {

        boolean flag;
        if (checked(table, data1, data2)) {
            flag = true;
            try {
                if (table == "user_class") {
                    String sql = "delete from " + table + " where s_class = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_course") {
                    String sql = "delete from " + table + " where s_course = '" + data1 + "'" + " and s_class = '" + data2 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_stu") {
                    String sql = "delete from " + table + " where s_no = '" + data1 + "'" + " and s_name = '" + data2 + "'";
                    System.out.println("delete from " + table + " where s_no = '" + data1 + "'" + " and s_name = '" + data2 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);
                } else if (table == "user_select") {


                } else if (table == "user_score") {
                    String sql = "delete from " + table + " where s_no = '" + data1 + "'" + " and s_course = '" + data2 + "'";
                    System.out.println("delete from " + table + " where s_no = '" + data1 + "'" + " and s_course = '" + data2 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);
                } else if (table == "user_score") {
                    String sql = "delete from " + table + " where s_no = '" + data1 + "'" + " and s_course = '" + data2 + "'";
                    System.out.println("delete from " + table + " where s_no = '" + data1 + "'" + " and s_course = '" + data2 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            flag = false;
        }
        return flag;
    }

    public static boolean delete(String table, String data1, String data2, String data3) {

        boolean flag;
        if (checked(table, data1, data2, data3)) {
            flag = true;

//            if (table == "user_course_public") {
//
//            } else if (table == "user_course_f") {
//
//            }

            if (data2 == "数学") {
                teacher = "牛牛";
            } else if (data2 == "体育") {
                teacher = "露露";
            } else if (data2 == "英语") {
                teacher = "唔唔";
            } else if (data2 == "Java") {
                teacher = "美美";
            } else if (data2 == "C++") {
                teacher = "嘟嘟";
            } else if (data2 == "神奇宇宙") {
                teacher = "舒舒";
            } else if (data2 == "生物进化论") {
                teacher = "谷谷";
            } else if (data2 == "Python程序") {
                teacher = "酷酷";
            } else if (data2 == "茶道") {
                teacher = "虎虎";
            } else if (data2 == "安卓应用") {
                teacher = "醋醋";
            }

            if (data3 == "2021-2022第一学期") {
                grade = "大二";
            } else if (data3 == "2021-2022第二学期") {
                grade = "大二";
            } else if (data3 == "2022-2023第一学期") {
                grade = "大三";
            }

            System.out.println(data1 + data2 + data3);
            System.out.println(teacher + grade);

            try {
                if (table == "user_class") {
                    String sql = "delete from " + table + " where s_class = '" + data1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_course") {
                    String sql = "delete from " + table + " where s_course = '" + data1 + "'" + " and s_class = '" + data2 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_stu") {
                    String sql = "delete from " + table + " where s_no = '" + data1 + "'" + " and s_name = '" + data2 + "'";
                    System.out.println("delete from " + table + " where s_no = '" + data1 + "'" + " and s_name = '" + data2 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);
                } else if (table == "user_course_public") {
                    String sql = "delete from " + table + " where s_class = '" + data1 + "'" + " and s_course = '" + data2 + "'" + " and s_semester = '" + data3 + "'";
                    System.out.println("delete from " + table + " where s_class = '" + data1 + "'" + " and s_course = '" + data2 + "'" + " and s_semester = '" + data3 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);

                } else if (table == "user_score") {
                    String sql = "delete from " + table + " where s_no = '" + data1 + "'" + " and s_course = '" + data2 + "'";
                    System.out.println("delete from " + table + " where s_no = '" + data1 + "'" + " and s_course = '" + data2 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);
                } else if (table == "user_course_f") {
                    String sql = "delete from " + table + " where s_course = '" + data1 + "'" + " and s_teacher = '" + data2 + "'" + " and s_semester = '" + data3 + "'";
                    System.out.println("delete from " + table + " where s_course = '" + data1 + "'" + " and s_teacher = '" + data2 + "'" + " and s_semester = '" + data3 + "'");
                    sm.executeUpdate(sql);
                    System.out.println(sql);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            flag = false;
        }
        return flag;
    }

    //************************************************ delete **********************************************************//

    //************************************************ modify **********************************************************//
    public static boolean modify(String table, String d1, String d2, String d3, String d4) {
        boolean flag;
        if (checked(table, d1)) {
            flag = true;
            try {
                if (table == "user_class") {
                    String sql = "update user_class set s_class ='" + d1 + "',s_grade = '" + d2 + "',s_num = '" + d3 + "',s_teacher='" + d4 + "' where s_class='" + d1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_course") {
                    String sql = "update user_course set s_class ='" + d2 + "',s_grade = '" + d3 + "',s_course = '" + d1 + "',s_teacher='" + d4 + "' where s_course='" + d1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_stu") {


                } else if (table == "user_select") {


                } else if (table == "user_score") {
                    String sql = "update user_score set s_no ='" + d1 + "',s_name = '" + d2 + "',s_course = '" + d3 + "',s_score='" + d4 + "' where s_no='" + d1 + "'";
                    sm.executeUpdate(sql);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            flag = false;
        }
        return flag;
    }

    public static boolean modify(String table, String d1, String d2, String d3, String d4, String d5) {
        boolean flag;
        if (checked(table, d1)) {
            flag = true;
            try {
                if (table == "user_class") {
                    String sql = "update user_class set s_class ='" + d1 + "',s_grade = '" + d2 + "',s_num = '" + d3 + "',s_teacher='" + d4 + "' where s_class='" + d1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_course") {
                    String sql = "update user_course set s_class ='" + d2 + "',s_grade = '" + d3 + "',s_course = '" + d1 + "',s_teacher='" + d4 + "' where s_course='" + d1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_stu") {
                    String sql = "update user_stu set s_no ='" + d1 + "',s_name = '" + d2 + "',s_class = '" + d3 + "',s_grade='" + d4 + "',s_major='" + d5 + "' where s_no='" + d1 + "'";
                    sm.executeUpdate(sql);
                } else if (table == "user_select") {


                } else if (table == "user_score") {
                    String sql = "update user_score set s_no ='" + d1 + "',s_name = '" + d2 + "',s_course = '" + d3 + "',s_score='" + d4 + "' where s_no='" + d1 + "'";
                    sm.executeUpdate(sql);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } else {
            flag = false;
        }
        return flag;
    }

//        String sql = "update user_class set s_class ='" + d1 + "',s_grade = '" + d2 + "',s_num = '" + d3 + "',s_teacher='" + d4 + "' where s_class='" + s_class + "'";
//        boolean flag = false;
//        try {
//            sm.executeUpdate(sql);
//            flag = true;
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//    public static boolean checkByUnameAndPwd(String sno, String pwd) {
//        String sql = "select * from user_info where s_no='" + sno + "' and s_password='" + pwd + "' ";
//        ResultSet rs = DBUtil.getResult(sql);
//        boolean flag = false;
//        try {
//            while (rs.next()) {
//                flag = true;
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return flag;
//    }
    //************************************************ modify **********************************************************//

    //************************************************checked**********************************************************//
    public static boolean checked(String table, String data1) {
        String d1 = null;
        if (table == "user_class") {
            d1 = "s_class";
        } else if (table == "user_course") {
            d1 = "s_course";
        } else if (table == "user_stu") {
            d1 = "s_no";
        } else if (table == "user_select") {
            d1 = "s_course";
        } else if (table == "user_score") {
            d1 = "s_no";
        } else if (table == "user_course_f") {
            d1 = "s_course";
        }

        String sql = "select * from " + table + " where " + d1 + " = '" + data1 + "' ";
        ResultSet rs = DBUtil.getResult(sql);
        boolean flag = false;
        try {
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }

    public static boolean checked(String table, String data1, String data2) {
        String d1 = null;
        String d2 = null;
        String d3 = null;
        if (table == "user_class") {
            d1 = "s_class";
        } else if (table == "user_course") {
            d1 = "s_course";
            d2 = "s_class";
        } else if (table == "user_stu") {
            d1 = "s_no";
        } else if (table == "user_select") {
            d1 = "s_course";
        } else if (table == "user_score") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_course_public") {
            d1 = "s_class";
            d2 = "s_course";
            d3 = "s_semester";
        }

        String sql = "select * from " + table + " where " + d1 + " = '" + data1 + "' and " + d2 + " = '" + data2 + "'";
        ResultSet rs = DBUtil.getResult(sql);
        boolean flag = false;
        try {
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }

    public static boolean checked(String table, String data1, String data2, String data3) {
        String d1 = null;
        String d2 = null;
        String d3 = null;
        if (table == "user_class") {
            d1 = "s_class";
        } else if (table == "user_course") {
            d1 = "s_course";
            d2 = "s_class";
        } else if (table == "user_stu") {
            d1 = "s_no";
        } else if (table == "user_select") {
            d1 = "s_course";
        } else if (table == "user_score") {
            d1 = "s_no";
            d2 = "s_course";
        } else if (table == "user_course_public") {
            d1 = "s_class";
            d2 = "s_course";
            d3 = "s_semester";
        } else if (table == "user_course_f") {
            d1 = "s_class";
            d2 = "s_course";
            d3 = "s_semester";
        }

        String sql = "select * from " + table + " where " + d1 + " = '" + data1 + "' and " + d2 + " = '" + data2 + "' and " + d3 + " = '" + data3 + "'";
        ResultSet rs = DBUtil.getResult(sql);
        boolean flag = false;
        try {
            while (rs.next()) {
                flag = true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return flag;
    }
}
